package com.kongzue.baseokhttpv3.slice;

import com.kongzue.baseokhttpv3.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

public class MainAbilitySlice extends AbilitySlice {
    private Text old, newtext;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_main_layout);
        initComent();
    }

    private void initComent() {
        old = (Text) findComponentById(ResourceTable.Id_oldtext);
        newtext = (Text) findComponentById(ResourceTable.Id_newtext);
        old.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.kongzue.baseokhttpv3")
                        .withAbilityName("com.kongzue.baseokhttpv3.MainAbility1")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        newtext.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.kongzue.baseokhttpv3")
                        .withAbilityName("com.kongzue.baseokhttpv3.MainAbility2")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
    }
}
